
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GetParen1 {
	public static final String PATTERN_UPDATE = "^update\\s+([\\w\\.\\s,-]+)\\s+\\bset\\b\\s+((?:.+=.+,)*(?:[\\w\\.-]+=[\\w\\.\\(\\),'-]+\\s+){1})\\bwhere\\b(.+)$";
	public static final String SRC_INPUT = "update rnd_test set a=b where c=d";

	public static void main(String[] args) {
		Pattern patt = Pattern.compile(PATTERN_UPDATE);
		// Pattern patt = Pattern.compile("\\w+\\s\\d+");
		Matcher matcher = patt.matcher(SRC_INPUT);
		while (matcher.find())
			System.out.println("group: " + matcher.group());

		matcher.reset();
		while (matcher.find()) {
			int i = matcher.groupCount();
			for (int j = 0; j <= i; ++j)
				System.out.println("group(" + j + "): " + matcher.group(j));
		}
	}
}
